package com.qjdchina.sku.biz.impl;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qjdchina.commons.enums.IsDeleted;
import com.qjdchina.commons.result.Result;
import com.qjdchina.sku.biz.RoleCategoryManager;
import com.qjdchina.sku.converter.RoleCategoryConverter;
import com.qjdchina.sku.dao.mapper.RoleCategoryMapper;
import com.qjdchina.sku.model.RoleCategory;
import com.qjdchina.sku.model.vo.RoleCategoryVO;
import com.qjdchina.sku.service.enums.SkuResultCode;

/**
 * 角色品类关联
 * @author shenpingfeng
 * 2017年2月14日
 */
@Service
public class RoleCategoryManagerImpl implements RoleCategoryManager {

	private static final Logger LOGGER = LoggerFactory.getLogger(RoleCategoryManagerImpl.class);

	@Autowired
	private RoleCategoryMapper roleCategoryMapper;
	

	
	@Override
	public Result<String> create(RoleCategoryVO roleCategoryVO) {
		if(roleCategoryVO == null){
			return new Result<String>(SkuResultCode.PARAMETER_NOT_EMPTY);
		}
		RoleCategory roleCategory = RoleCategoryConverter.toRoleCategory(roleCategoryVO);
		roleCategory.setGmtCreated(new Date());
		roleCategory.setGmtModified(new Date());
		roleCategory.setIsDeleted(IsDeleted.NO.getValue());
		int row = roleCategoryMapper.insertSelective(roleCategory);
		if(row == 0){
			return new Result<String>(SkuResultCode.ADD_FAIL);
		}
		
		return new Result<String>(row+"");
	}


	

}
